"use strict";
const a = require("../../common/vendor.js"),
  e = require("../../api/request.js");
Math || t();
const t = () => "../Common-components/my-work.js",
  n = {
    __name: "mine",
    setup(t) {
      const n = a.ref([{
          num: 0,
          title: "获赞"
        }, {
          num: 0,
          title: "关注"
        }, {
          num: 0,
          title: "粉丝"
        }]),
        o = a.ref([{
          title: "编辑资料",
          route: "/pages/personal-data/personal"
        }, {
          title: "密码设置",
          route: "/pages/password-settings/password"
        }]),
        u = a.reactive({
          avatarUrl: "",
          backdrop: "",
          nickname: "",
          age: "",
          city: "",
          uid: ""
        }),
        l = a.ref([]);
      a.onLoad((async () => {
        a.index.$on("loginSuccess", (async a => {
          await c()
        })), a.index.$on("uploadUserdata", (async a => {
          s()
        })), await c()
      }));
      const i = a.ref(!0),
        r = a.ref(!0);
      async function c() {
        try {
          y.value = 1, g.value = 0;
          const a = await e.requestApi("/my_related"),
            t = await e.requestApi("/myTravEls", {
              page: 1
            });
          console.log(t), l.value = t.data;
          const {
            concernCount: o,
            fansCount: u,
            likeCount: c
          } = a.data;
          n.value[0].num = c, n.value[1].num = o, n.value[2].num = u, r.value = !0, i.value = !1, s()
        } catch (a) {
          console.log(a), "401" == a && (r.value = !1, u.backdrop = "https://diancan-1252107261.cos.accelerate.myqcloud.com/lvyou/1681234407965-700945.jpg", u.avatarUrl = "https://diancan-1252107261.cos.accelerate.myqcloud.com/lvyou/1681234402293-9911580.jpg", u.nickname = "点击登录"), i.value = !1
        }
      }

      function s() {
        const {
          avatarUrl: e,
          backdrop: t,
          nickname: n,
          uid: o,
          age: l,
          city: i
        } = a.index.getStorageSync("userInfor");
        u.avatarUrl = e, u.backdrop = t, u.nickname = n, u.uid = o, u.age = l, u.city = i
      }
      const v = a.ref(["作品", "收藏", "喜欢"]),
        p = a.ref(["/myTravEls", "/myCollEction", "/myLikeArticle"]),
        g = a.ref(0),
        d = a.ref(["你还没有发布作品", "快去收藏游记吧", "你还没有喜欢的游记"]),
        m = a.ref("你还没有发布作品");
      async function f(a) {
        const t = a.currentTarget.dataset.index;
        if (g.value = t, m.value = d.value[g.value], y.value = 1, 0 === t) {
          const a = await e.requestApi(p.value[0], {
            page: 1
          });
          l.value = a.data
        } else if (1 === t) {
          const a = await e.requestApi(p.value[1], {
            page: 1
          });
          l.value = a.data
        } else {
          const a = await e.requestApi(p.value[2], {
            page: 1
          });
          l.value = a.data
        }
      }
      const y = a.ref(1);

      function w() {
        r.value || a.wx$1.navigateTo({
          url: "/pages/Login-pop-up/login"
        })
      }

      function k() {
        if (!r.value) return a.wx$1.navigateTo({
          url: "/pages/Login-pop-up/login"
        }), !1;
        a.wx$1.navigateTo({
          url: "/pages/personal-data/personal"
        })
      }
      return a.onReachBottom((async () => {
        y.value++;
        const a = p.value[g.value],
          t = await e.requestApi(a, {
            page: y.value
          });
        l.value = [...l.value, ...t.data]
      })), (e, t) => a.e({
        a: u.backdrop,
        b: a.o(k),
        c: u.avatarUrl,
        d: a.o(k),
        e: a.t(u.nickname),
        f: a.o(w),
        g: a.f(n.value, ((e, t, n) => ({
          a: a.t(e.num),
          b: a.t(e.title),
          c: t
        }))),
        h: "" != u.age
      }, "" != u.age ? {
        i: a.t(u.age)
      } : {}, {
        j: "" != u.city
      }, "" != u.city ? {
        k: a.t(u.city)
      } : {}, {
        l: u.uid
      }, u.uid ? {
        m: a.t(u.uid)
      } : {}, {
        n: a.f(o.value, ((e, t, n) => ({
          a: a.t(e.title),
          b: t,
          c: a.o((t => function (e, t) {
            if (!r.value) return a.wx$1.navigateTo({
              url: "/pages/Login-pop-up/login"
            }), !1;
            a.wx$1.navigateTo({
              url: e
            })
          }(e.route)), t)
        }))),
        o: a.f(v.value, ((e, t, n) => ({
          a: a.t(e),
          b: g.value === t ? 1 : "",
          c: g.value === t ? 1 : "",
          d: t,
          e: t,
          f: a.o(f, t)
        }))),
        p: a.p({
          userTravels: l.value,
          tip: m.value
        })
      })
    }
  };
wx.createPage(n);